﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Shell.DomainDot;
using Framework.Poco;
using Framework.Domain;

namespace Framework.Mvc.Controllers
{
    /// <summary>
    /// 经销商分组基本信息
    /// </summary>
    public class GroupAgencyBaseInformationController : Controller
    {
        private IDomainDotFactory factory;

        /// <summary>
        /// 构造器
        /// </summary>
        public GroupAgencyBaseInformationController()
        {
            factory = DomainDotFactory.Factory;
        }

        /// <summary>
        /// 酒店基本信息
        /// </summary>
        [HttpGet]
        public ActionResult HotelBaseInformation(Agency currentAgency)
        {
            if (currentAgency != null)
            {
                var model = new HotelBaseInformationViewModel();
                var globalContext = factory.Create<GlobalContext>();
                var hotelContext = factory.Create<HotelInAgency>(currentAgency.Id);
                model.Instance = hotelContext.GetHotel();
                model.AvailableChurchWeddings = globalContext.GetAllChurchWeddings();
                model.AvailableFeaturedWeddings = globalContext.GetAllFeaturedWeddings();
                return View(model);
            }
            return this.RedirectToAction("LogOn", "Agency");
        }

        /// <summary>
        /// 酒店基本信息
        /// </summary>
        [HttpPost]
        public ActionResult HotelBaseInformation(Agency currentAgency, HotelBaseInformationViewModel model)
        {
            if (currentAgency != null)
            {
                var context = factory.Create<HotelInAgency>(currentAgency.Id);
                context.Create(model.Instance, model.FeaturedWeddingIdentity, model.ChurchWeddingIdentity);
                var script = String.Format("<script>alert('修改成功!');location.href='{0}'</script>", Url.Action("HotelBaseInformation"));
                return Content(script);
            }
            return this.RedirectToAction("Logon", "Agency");
        }

        /// <summary>
        /// 酒店大厅基本信息
        /// </summary>
        [HttpGet]
        public ActionResult HotelHall(Agency currentAgency)
        {
            if (currentAgency != null)
            {
                var model = new HotelHallViewModel();
                var context = factory.Create<GlobalContext>();
                model.AvailableConsumptionClass = context.GetAllConsumptionClass();
                model.AvailableServiceCosts = context.GetAllServiceCosts();
                return View(model);
            }
            return this.RedirectToAction("LogOn", "Agency");
        }

        /// <summary>
        /// 酒店大厅基本信息
        /// </summary>
        [HttpPost]
        public ActionResult HotelHall(Agency currentAgency, HotelHallViewModel model)
        {
            if (currentAgency != null)
            {
                var context = factory.Create<HotelHallContext>();
                context.Create(model.Instance, model.ServiceCostsIdentity, model.ConsumptionClassIdentity, model.NextYearPrices);
                return View();
            }
            return this.RedirectToAction("LogOn", "Agency");
        }
    }
}
